<template>
	<view>
		<cu-custom bgColor="bg-rgb" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">新增无效时间</block>
		</cu-custom>
		<form>
			<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: 0.1 + 's'}]">
				<view class="title">制令单：</view>
				<input placeholder="请输入制令单" name="input" v-model="myFormData.commandBill"></input>
			</view>
			<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: 0.2 + 's'}]">
				<view class="title">线别：</view>
				<input placeholder="请输入线别" name="input" v-model="myFormData.lineType"></input>
			</view>
			<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: 0.3 + 's'}]">
				<view class="title">维护人：</view>
				<input placeholder="请输入维护人" name="input" v-model="myFormData.repairPerson"></input>
			</view>
			<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: 0.4 + 's'}]">
				<view class="title">工单：</view>
				<input placeholder="请输入工单" name="input" v-model="myFormData.workBill"></input>
			</view>
			<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: 0.5 + 's'}]">
				<view class="title">停线类型：</view>
				<input placeholder="请输入停线类型" name="input" v-model="myFormData.staylineType"></input>
			</view>
			<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: 0.6 + 's'}]">
				<view class="title">开始时间</view>
				<view class="" @click="start">
					{{startString}}
				</view>
			</view>
			<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: 0.7 + 's'}]">
				<view class="title">结束时间</view>
				<view class="" @click="end">
					{{endString}}
				</view>
			</view>
			<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: 0.8 + 's'}]">
				<view class="title">维护原因：</view>
				<input placeholder="请输入维护原因" name="input" v-model="myFormData.repairReason"></input>
			</view>
			<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: 0.9 + 's'}]">
				<view class="title">审核意见：</view>
				<input placeholder="请输入审核意见" name="input" v-model="myFormData.verifyOpinion"></input>
			</view>
			<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: 1.0 + 's'}]">
				<view class="title">审核结果：</view>
				<input placeholder="请输入审核结果" name="input" v-model="myFormData.verifyResult"></input>
			</view>
			<view class="padding flex flex-direction animation-slide-bottom" :style="[{animationDelay: 0.9 + 's'}]">
				<button class="cu-btn bg-rgb lg" @click="onSubmit">添加</button>
			</view>
		</form>
		<w-picker :visible.sync="visible" mode="date" startYear="2017" endYear="2229" :value="myFormData.endStayline" :current="true"
		 fields="second" @confirm="onConfirm($event,'start')" @cancel="onCancel" :disabled-after="false" ref="date"></w-picker>
		<w-picker :visible.sync="visible1" mode="date" startYear="2017" endYear="2229" :value="myFormData.endStayline" :current="true"
		 fields="second" @confirm="onConfirm($event,'end')" @cancel="onCancel" :disabled-after="false" ref="date1"></w-picker>
	</view>
</template>

<script>
	import wPicker from "@/components/w-picker/w-picker.vue";
	export default {
		components: {
			wPicker
		},
		data() {
			return {
				myFormData: {
					commandBill: '', // 制令单
					lineType: '', // 线别
					repairPerson: '', // 维护人
					workBill: '', //工单
					staylineType: '', // 停线类型
					repairReason: '', // 维护原因
					verifyOpinion: '', // 审核意见
					verifyResult: '', // 审核结果
					startStayline: '', // 开始停线时间
					endStayline: ''
				},
				startString: '请选择开始时间',
				endString: '请选择结束时间',
				visible: false,
				visible1: false
			};
		},
		onLoad: function(option) {
			console.log(JSON.stringify(uni.getStorageSync('login_user_info')).realname)
		},
		methods: {
			start() {
				this.$refs.date.show()
			},
			end() {
				this.$refs.date1.show()
			},
			onConfirm(e, date) {
				console.log(e, date)
				if (date == 'start') {
					this.startString = e.value
					this.myFormData.startStayline = e.value
				} else {
					this.endString = e.value
					this.myFormData.endStayline = e.value
				}
			},
			onCancel() {
			
			},
			onSubmit() {
				uni.showModal({
					title: '无效时间',
					content: '确定要添加无效时间吗？',
					cancelText: '取消',
					confirmText: '确定',
					success: res => {
						if (res.confirm) {
							if (this.myFormData.commandBill.replace(/\s+/g, "") == '') {
								// this.$tip.error('制令单不能为空');
								this.modal.show({ type:'error', content:'制令单不能为空' })
								return false
							} else if (this.myFormData.lineType.replace(/\s+/g, "") == '') {
								// this.$tip.error('线别不能为空');
								this.modal.show({ type:'error', content:'线别不能为空' })
								return false
							} else if (this.myFormData.repairPerson.replace(/\s+/g, "") == '') {
								// this.$tip.error('维护人不能为空');
								this.modal.show({ type:'error', content:'维护人不能为空' })
								return false
							} else if (this.myFormData.workBill.replace(/\s+/g, "") == '') {
								// this.$tip.error('工单不能为空');
								this.modal.show({ type:'error', content:'工单不能为空' })
								return false
							} else if (this.myFormData.staylineType.replace(/\s+/g, "") == '') {
								// this.$tip.error('停线类型不能为空');
								this.modal.show({ type:'error', content:'停线类型不能为空' })
								return false
							} else if (this.myFormData.repairReason.replace(/\s+/g, "") == '') {
								// this.$tip.error('维护原因不能为空');
								this.modal.show({ type:'error', content:'维护原因不能为空' })
								return false
							} else if (this.myFormData.verifyOpinion.replace(/\s+/g, "") == '') {
								// this.$tip.error('审核意见不能为空');
								this.modal.show({ type:'error', content:'审核意见不能为空' })
								return false
							}else if (this.myFormData.verifyResult.replace(/\s+/g, "") == '') {
								// this.$tip.error('审核结果不能为空');
								this.modal.show({ type:'error', content:'审核结果不能为空' })
								return false
							}else if (this.myFormData.startStayline.replace(/\s+/g, "") == '') {
								// this.$tip.error('开始停线时间不能为空');
								this.modal.show({ type:'error', content:'开始停线时间不能为空' })
								return false
							}else if (this.myFormData.endStayline.replace(/\s+/g, "") == '') {
								// this.$tip.error('结束停线时间不能为空');
								this.modal.show({ type:'error', content:'结束停线时间不能为空' })
								return false
							}
							console.log(this.myFormData)
							uni.showLoading({
								mask:true,
								title:'添加中.....'
							})
							let mesTempratureGraph = this.myFormData
							this.$http.post('produce/mesInvalidTime/add', mesTempratureGraph).then(res => {
								console.log(res)
								uni.hideLoading()
								if (res.data.success) {
									// this.$tip.success(res.data.message);
									this.modal.show({ type:'success', content:res.data.message })
									setTimeout(function() {
										uni.navigateBack({
											delta: 1
										})
									}, 1000);
								} else {
									// this.$tip.error(res.data.message)
                  this.modal.show({ type:'error', content:res.data.message })
								}
							})
						}
					}
				})
			}
		}
	}
</script>

<style>
	.cu-form-group .title {
		min-width: calc(4em + 15px);
	}

	.btn {
		background-color: rgb(0, 64, 152);
		padding: 10rpx;
		color: white;
		border-radius: 10rpx;
	}

	input {
		text-align: right;
	}
</style>
